/*
		mycar/cyber 검색
*/


// 사이버 우편번호 검색
// 가려진 창과 같이 변경
function zipcode_new(sido) {

			var dummy   = new Date().getTime();
			var sidoUrl = encodeURI(sido);

			var addr_level  = 2;
			var addr_sel_no = 9;
			var label_txt   = "구/군";
			
			var url_param   = "sido=" + sidoUrl;
			        
			if(arguments[1]) {
				addr_level  = arguments[1];
				addr_sel_no = arguments[2];
				
				if(addr_level == 3) {
					var sido_param = arguments[3];
					var label_txt   = "전체";
					url_param   = "sido=" + sido_param + "&gparam=" + sidoUrl;
				}
				
			}

      var gdetail = arguments[4];

			$.ajax({
  				type: 'get'
  				, async: true
  				, url: '/mycar/proc/sido.php'
  				, data: url_param
  				, dataType: 'json'
  				, beforeSend: function() {
  				     //$('#ajax_load_indicator').show().fadeIn('fast');
  				  }
  				, success: function(data) {
  		 		    var response = data;

							$("#addr_"+ addr_level +" option").remove();
							$("#addr_"+ addr_level).append('<option value="">전체</option>');

							$("#addr_"+ addr_level + "_detail" +" option").remove();
							$("#addr_"+ addr_level + "_detail").append('<option value="">전체</option>');


							$.each(response, function(val) {
								$("#addr_"+ addr_level).append('<option value="' + response[val] + '">' + response[val] + '</option>');
								$("#addr_"+ addr_level + "_detail").append('<option value="' + response[val] + '">' + response[val] + '</option>');
								
								
							});
							
							
								if(gdetail == 'detail') {
									//디테일 텍스트
									$(".selstrong").eq(addr_sel_no).text(label_txt);	
									//일반보기 텍스트
									$("#addr_" + (addr_level - 1)).val($("#addr_" + (addr_level - 1) + "_detail").val());
									$(".selstrong").eq(addr_sel_no - 13).text($("#addr_" + (addr_level - 1) + "_detail").val());		
									$(".selstrong").eq(addr_sel_no - 12).text(label_txt);	
								} else {
									//일반보기 텍스트
									$(".selstrong").eq(addr_sel_no).text(label_txt);	
									//디테일 텍스트
									$("#addr_" + (addr_level - 1) + "_detail").val($("#addr_" + (addr_level - 1)).val());
									$(".selstrong").eq(addr_sel_no + 11).text($("#addr_" + (addr_level - 1)).val());		
									$(".selstrong").eq(addr_sel_no + 12).text(label_txt);	
								}

							
 				  	}
  				, error: function(data, status, err) {
  				    alert('서버와의 통신이 실패했습니다.' + err);

  				  }
  				, complete: function() {
  					//$('#ajax_load_indicator').fadeOut();
  				  }
  		});
}


function zipcode_new_second(obj) {
	var sel_no2 = "";
	
	var id1 = "";
	var id2 = "";
	
	if(obj.substr(-7) == '_detail') {
		id1 = obj;
		id2 = obj.substr(0, obj.length - 7);
	} else {
		id1 = obj;
		id2 = obj + "_detail";
	}	
	
	sel_no2 = $("select").index( $("#" + id2) );

  $(".selstrong")
         .eq(sel_no2)
         .text($('#' + id1 + ' option:selected').text());

	$('#' + id2).val($('#' + id1).val());	
}

// 그룹된 모델 토글
function model_Toggle(obj, single) {
	
	var tStatus = "";
	//$("#model_no").val('');
	$.each( $("a[id*='toggle_']") , function() {
		  if(	this.className == "choice") {
		  	$("#" + this.id).removeClass('choice');
		  } 
	});

	$.each( $("img[id*='toggle_img_']") , function() {
		  if(	this.src == "http://image.bobaedream.co.kr/renew/images/common_re/bullet06.gif") {
		  	this.src = "http://image.bobaedream.co.kr/renew/images/common_re/bullet05.gif";
		  } 
	});

	
	// 모델 +, -
	if( $("#ul_model_" + obj).css("display") == "none" ) {
		tStatus = "";
		if(single != 1) {
			$("#toggle_" + obj).addClass('choice');
			$("#toggle_img_" + obj).attr("src", "http://image.bobaedream.co.kr/renew/images/common_re/bullet06.gif");
		} else {
			$("#toggle_" + obj).removeClass('choice');
		}
	} else {
		tStatus = "none";
		if(single != 1) {  
			$("#toggle_" + obj).removeClass('choice');
			$("#toggle_img_" + obj).attr("src", "http://image.bobaedream.co.kr/renew/images/common_re/bullet05.gif");
		} else {
			$("#toggle_" + obj).addClass('choice');
		}
	}

	$("ul[id*='ul_model_']").hide();
	$("input:checkbox[id*='model_chk_']").attr("checked", false);
	$("#ul_model_" + obj).css("display", tStatus);

}

// 리스트 초기화
function divClear(mk_div, obj, remove) {
		var st = obj;
		var lst_arr     = new Array(mk_div, "model_div", "level_div", "level2_div");
		var lst_txt_arr = new Array("", 
																"<li class=\"guidetextimg\"><img src=\"http://image.bobaedream.co.kr/renew/images/common_re/mycarsearchtext01.gif\" alt=\"\" title=\"제조사를 선택하시면 리스트가 열립니다.\" /></li>", 
																"<li class=\"guidetextimg\"><img src=\"http://image.bobaedream.co.kr/renew/images/common_re/mycarsearchtext02.gif\" alt=\"\" title=\"모델 선택하시면 리스트가 열립니다.\" /></li>", 
																"<li class=\"guidetextimg\"><img src=\"http://image.bobaedream.co.kr/renew/images/common_re/mycarsearchtext04.gif\" alt=\"\" title=\"세부모델을 선택하시면 리스트가 열립니다.\" /></li>"
																);

		if(remove != undefined) {
			st = obj/1 + remove/1;
		}
				
		for(var i=st; i<=3; i++) {
	  		$("#" + lst_arr[i] + " li").remove();
	  		$("#" + lst_arr[i] + " ul").remove();
  			$("#" + lst_arr[i] + " p").remove();
		}
  			
		for(var i=obj; i<=3; i++) {

  			if ( (i/1) > obj && (i/1) <= 3 ) {
					
  				$("#" + lst_arr[i]).append(lst_txt_arr[i]);
  			}
  	}
}

// 차종
function carriage_i(strcar) {
	$("#carriage").val(strcar);
}

// 모델 선택 시
function model_click(obj1, obj2, obj3) {
	divClear(mk_div, '\''  + obj2 + '\'', '1');
	model_Toggle(obj2, 1);
	$('#model_chk_' + obj3).attr('checked', 'true')

}


// 검색

/*

	- car_depth param -
no           -
name         - 해당 이름 x
dep          - 제조사:0, 모델:1, 등급:2, 세부등급:3
sort         - 선택한 순번
cnt          - 전체수
tab          - 차종

// mycar_list_search.php에 설정된 자바스크립트 변수
gubun        - 국산/수입       
ot           - 차종검색
mk_div       - 제조사, 차종 DIV
mk_sort_div  - 제조사, 차종 정렬 DIV
mk_no        -  
mk_title     - 

*/


function car_depth(no, dep, sort, sortType) {
	
			var dummy     = new Date().getTime();
			var carr = $('#carriage').val();

			// , data: "dummy=" + dummy + "&no=" + no + "&dep=" + dep

			  if( (dep/1 - 1) == 0 || (dep/1 - 1) == 10) {
			  	var mklistsel = $("a[id*='car_kind_']"); 
			  	
			  	mklistsel.removeClass('choice');
			  	$("#car_kind_" + sort).addClass('choice'); 
			  }


				if(dep == 2) {

						var model_select_cnt = $("input:checkbox[id*='model_chk_']:checked");    
					 	if(model_select_cnt.length != undefined && model_select_cnt.length == 1) {
					 		no = model_select_cnt[0].value;
					 	}
				}			
        
				if(dep == 3) {
					
						var level_select_cnt = $("input:checkbox[id*='level_chk_']:checked");				
					 	if(level_select_cnt.length != undefined && level_select_cnt.length == 1) {
					 		no = level_select_cnt[0].value;
					 	}
				}			

				$.ajax({
  					type: 'get'
  					, async: true
  					, url: '/mycar/proc/ajax_maker.php'
  					, data: "dummy="     + dummy            + 
  									"&no="       + no               + 
  									"&dep="      + dep              + 
  									"&tab="      + tab              + 
  									"&carriage=" + encodeURI(carr)  + 
  									"&sortType=" + sortType         + 
  									"&cartype="  + gubun            +
  									"&ot="       + ot
  					, dataType: 'json'
  					, beforeSend: function() {
  					     //$('#ajax_load_indicator').show().fadeIn('fast');
  					  }
  					, success: function(data) {
  			 		    var response = data;
  			 		    var temp_txt = "";
  			 		    var temp_tot = 0;
  			 		    var seg      = "";
  			 		    var atagID   = 1;

  			 		    
  			 		    // 제조사 출력
  			 		    if(dep == 0 || dep == 10) {
  			 		    		if(dep == 10) {
  			 		    			// 차종검색일 경우
											dep = 0;
											seg = true;
  			 		    		}

										//출력된 리스트들 지우기
										divClear(mk_div, dep);

										// 정렬방식 인기순, 매물순
										var gb_num = 1;
										if(gubun == 'I') {
											gb_num = 0;
										}
										
										if(sortType == 1) {
											//$("#" + mk_sort_div).html('<a href="javascript:car_depth(' + gb_num + ',  mk_no, 1, 1);" class="on">인기순</a> <a href="javascript:car_depth(' + gb_num + ', mk_no, 1, 2);" >매물순</a>\n');
											$("#" + mk_sort_div).html('<span class="sortline"><a href="javascript:car_depth(' + gb_num + ',  mk_no, 1, 1);"><span class="choice">이름순</span></a></span><a href="javascript:car_depth(' + gb_num + ', mk_no, 1, 2);">인기순</a>');
										} else if(sortType == 2) {
											//$("#" + mk_sort_div).html('<a href="javascript:car_depth(' + gb_num + ',  mk_no, 1, 1);">인기순</a> <a href="javascript:car_depth(' + gb_num + ', mk_no, 1, 2);" class="on">매물순</a>\n');
											$("#" + mk_sort_div).html('<span class="sortline"><a href="javascript:car_depth(' + gb_num + ',  mk_no, 1, 1);">이름순</a></span><a href="javascript:car_depth(' + gb_num + ', mk_no, 1, 2);"><span class="choice">인기순</span></a>'); 
										}

										if(dep == 0) {
											$("#tab").val('');
										}										
										// response[val]['sort'] 정렬 시 a 테그 선택을 위해 변경
 			 		    			$.each(response, function(val) {
											if(seg == true) {
												temp_txt += '<li><a id="car_kind_' + response[val]['sort'] + '" href="javascript:carriage_i(\'' + response[val]['name'] + '\');car_depth(\'' + response[val]['no'] + 
																		'\', '   + response[val]['depth']                            + 
																		', '     + response[val]['sort']                             + 
																		');">'   + response[val]['name']                             + 
																		'</a></li>\n';                                
											} else {				
												temp_txt += '<li><a id="car_kind_' + response[val]['sort'] + '" href="javascript:car_depth(\'' + response[val]['no'] + 
																		'\', '   + response[val]['depth']                            + 
																		', '     + response[val]['sort']                             + 
																		');">'   + response[val]['name']                             + 
																		'</a></li>\n';            
											}
											atagID++;                    
										});  

										$("#" + mk_div ).append('<ul id="seg_ul" class="result01">' + temp_txt + '</ul>\n');

  			 		    } else if(dep == 1 || dep == 11) { 
  			 		    		var seg         = "";
  			 		    		var model_name  = "";
  			 		    		var resp_dep    = "";
  			 		    		var seg_mk_name = "";
										
										// class=last
										var model_size  = 0;
										var model_size_cnt = 0;
										var model_size_class = "";	
											
										var sort_div_txt = '<a href="javascript:car_depth(\'' + no + '\', ' + dep + ', ' + sort + ', ';
  			 		    		
  			 		    		if(dep == 11) {
  			 		    			// 차종검색일 경우
  			 		    			seg = true;
											dep = 1;
  			 		    			tab = sort + 1;	
  			 		    			$('#tab').val(tab);
  			 		    		} else {
  			 		    			// 모델 검색일 경우만 값을 넣어준다
  			 		    			$("#maker_no").val(no);
  			 		    		}

										divClear(mk_div, dep);

										$("#model_sort_div a").remove();											

										if(sortType == 1 || sortType == undefined) {
											$("#model_sort_div").html( '<span class="sortline">' + sort_div_txt + '1 );"><span class=\"choice\">이름순</span></a></span> <span class=\"sortline choice\">' + sort_div_txt +  '2);" ><span class=\"\">인기순</span></a></span> ' + sort_div_txt + '3);" ><span class=\"\">출시순</span></a> \n');
										} else if(sortType == 2) {
											$("#model_sort_div").html( '<span class="sortline">' + sort_div_txt + '1 );"><span class=\"\">이름순</span></a></span> <span class=\"sortline choice\">' + sort_div_txt +  '2);" ><span class=\"choice\">인기순</span></a></span> ' + sort_div_txt + '3);" ><span class=\"\">출시순</span></a> \n');
										} else if(sortType == 3) {
											$("#model_sort_div").html( '<span class="sortline">' + sort_div_txt + '1 );"><span class=\"\">이름순</span></a></span> <span class=\"sortline choice\">' + sort_div_txt +  '2);" ><span class=\"\">인기순</span></a></span> ' + sort_div_txt + '3);" ><span class=\"choice\">출시순</span></a> \n');											
										}
										
  			 		    		$.each(response, function(val) {
                		
											temp_txt 	 = "";
											temp_tot 	 = 0;
										  seg_mk_name = "";	
											
											if( response[val]['model'].length == 1) {

													$.each(response[val]['model'] , function(models) {
														
															model_name = response[val]['name'];
															resp_dep   = response[val]['model'][models]['depth'];
															
                							if(seg == true) {
                								model_name  = response[val]['model'][models]['name'];
                								resp_dep    = dep + 1;
                								seg_mk_name = response[val]['model'][models]['maker_name'] + ' - ';
                							}

															temp_tot += response[val]['model'][models]['cnt'];
															temp_txt += '<input type="checkbox" name="model_no[]" id="model_chk_' +
																						response[val]['model'][models]['no'] + '" value="'   		 +
																						response[val]['model'][models]['no']                 		 +
																						'" style="display:none">\n';                                                     


 															$("#model_div").append('<li id="li_model_'     + val             + 
																	'"><a id="toggle_' + val + '" href="javascript:model_click(\'' + (dep/1) + '\', \'' + val + '\' , \'' + response[val]['model'][models]['no'] + '\');car_depth(\'' + 
																	response[val]['model'][models]['no'] + 
																	'\',  \''   + resp_dep                                              	         + 
																	'\',  \''   + response[val]['model'][models]['sort']                 	         + 
											  			    '\');">'    + seg_mk_name + model_name					                               +                      
																	'</a>' + temp_txt + '</li>\n');                                                    
                        			});
											} else {
												
													
													model_size = response[val]['model'].length;
													model_size_cnt = 0;
													model_size_class = "";
													
													$.each(response[val]['model'] , function(models) {
																
																if(model_size == (model_size_cnt + 1) ){
																	model_size_class = "last";
																} else {
																	model_size_class = "";
																}
																
																resp_dep   = response[val]['model'][models]['depth'];
																
                								if(seg == true) {
                									resp_dep    = dep + 1;
                									seg_mk_name = response[val]['model'][models]['maker_name'] + ' - '; 
                								}
																
																temp_tot += response[val]['model'][models]['cnt'];
																temp_txt += '<li class="' + model_size_class + '"><input type="checkbox" name="model_no[]" id="model_chk_'                  + 
																											response[val]['model'][models]['no'] + '" value="'                   + 
																											response[val]['model'][models]['no']                                 + 
																											'" onclick="car_depth(\'' + response[val]['model'][models]['no']     + 
																											'\',  \''   + resp_dep                                               + 
																											'\',  \''   + response[val]['model'][models]['sort']                 + 
																											'\')"><label for="model_chk_' + response[val]['model'][models]['no'] + 
																											'" style="cursor:pointer">&nbsp;' + response[val]['model'][models]['name'] + 
																											'</label></li>\n'; 
																											
															model_size_cnt++;																											
																											                               
													});
													
 													
 													$("#model_div").append('<li id="li_model_'  + val           							                                 + 
																								 '"><a id="toggle_'                     + val           							               + 
																								 '" href="javascript:divClear(mk_div, \''       + (dep/1)      				               + 
																								 '\', \'1\');model_Toggle(\''  + val           							               + 
																								 '\')" ><span class="carmodel">'                 + 
																								 seg_mk_name + response[val]['name']                                                 + 
																								 '</span><img id="toggle_img_' + val + '" src="http://image.bobaedream.co.kr/renew/images/common_re/bullet05.gif"' +
																								 ' title="분류닫기"  alt="분류닫기" class="btn" /></a><ul id="ul_model_' + val         + 
																								 '" class="result02re" style="display:none">\n'       							                   + 
																								 temp_txt + '</ul></li>\n');
                			}  		
 											
										});  
										

								} else if(dep == 2) {
											
											divClear(mk_div, dep);
											
											var sort_div_txt = '<a href="javascript:car_depth(\'' + no + '\',  ' + dep + ', ' + sort + ', ';
                    	
											$("#level_sort_div a").remove();											
                    	
											if(sortType == 1 || sortType == undefined) {
												$("#level_sort_div").html( '<span class="sortline">' + sort_div_txt + '1 );"><span class=\"choice\">이름순</span></a></span> <span class=\"sortline choice\">' + sort_div_txt +  '2);" ><span class=\"\">인기순</span></a></span> ' + sort_div_txt + '3);" ><span class=\"\">출시순</span></a> \n');
											} else if(sortType == 2) {
												$("#level_sort_div").html( '<span class="sortline">' + sort_div_txt + '1 );"><span class=\"\">이름순</span></a></span> <span class=\"sortline choice\">' + sort_div_txt +  '2);" ><span class=\"choice\">인기순</span></a></span> ' + sort_div_txt + '3);" ><span class=\"\">출시순</span></a> \n');
											} else if(sortType == 3) {
												$("#level_sort_div").html( '<span class="sortline">' + sort_div_txt + '1 );"><span class=\"\">이름순</span></a></span> <span class=\"sortline choice\">' + sort_div_txt +  '2);" ><span class=\"\">인기순</span></a></span> ' + sort_div_txt + '3);" ><span class=\"choice\">출시순</span></a> \n');											
											}

											if(model_select_cnt.length == 1) {
  			 		    				
  			 		    				$.each(response, function(val) {
																
												temp_txt += '<li><input type="checkbox" name="level_no[]" id="level_chk_'       + 
																							response[val]['no'] + '" value="'                         + 
																							response[val]['no']                                       +
																							'" onclick="car_depth(\'' + response[val]['no']           + 
																							'\',  \''   + response[val]['depth']                      + 
																							'\',  \''   + response[val]['sort']                       + 
																							'\')"><label style=\"cursor:pointer\" for="level_chk_'    + 
																							response[val]['no']  + '">&nbsp;' + response[val]['name'] + 
																							'</label></li>\n';                                
												});  
												$("#level_div").append(temp_txt + '\n');
												
											} else if(model_select_cnt.length > 1){
												$("#level_div").append('<li class=\"guidetextimg\"><img src=\"http://image.bobaedream.co.kr/renew/images/common_re/mycarsearchtext05.gif\" alt=\"\" title=\"모델 선택하시면 리스트가 열립니다.\" /></li>\n');
											} else if(model_select_cnt.length == 0){
												$("#level_div").append('<li class=\"guidetextimg\"><img src=\"http://image.bobaedream.co.kr/renew/images/common_re/mycarsearchtext02.gif\" alt=\"\" title=\"모델 선택하시면 리스트가 열립니다.\" /></li>\n');
											}
											
											
											
									}	else if(dep == 3) {
									
  			 		    			divClear(mk_div, dep);									

											//var level_select_cnt = $("input:checkbox[id*='level_chk_']:checked");

											var sort_div_txt = '<a href="javascript:car_depth(\'' + no + '\', ' + dep + ', ' + sort + ', ';
                    	
											$("#level2_sort_div a").remove();											

											if(sortType == 1 || sortType == undefined) {
												$("#level2_sort_div").html( '<span class="sortline">' + sort_div_txt + '1 );"><span class=\"choice\">이름순</span></a></span> <span class=\"sortline choice\">' + sort_div_txt +  '2);" ><span class=\"\">인기순</span></a></span> ' + sort_div_txt + '3);" ><span class=\"\">출시순</span></a> \n');
											} else if(sortType == 2) {
												$("#level2_sort_div").html( '<span class="sortline">' + sort_div_txt + '1 );"><span class=\"\">이름순</span></a></span> <span class=\"sortline choice\">' + sort_div_txt +  '2);" ><span class=\"choice\">인기순</span></a></span> ' + sort_div_txt + '3);" ><span class=\"\">출시순</span></a> \n');
											} else if(sortType == 3) {
												$("#level2_sort_div").html( '<span class="sortline">' + sort_div_txt + '1 );"><span class=\"\">이름순</span></a></span> <span class=\"sortline choice\">' + sort_div_txt +  '2);" ><span class=\"\">인기순</span></a></span> ' + sort_div_txt + '3);" ><span class=\"choice\">출시순</span></a> \n');											
											}


											
											if(level_select_cnt.length == 1) {
												
												
												if( response == null ) {
													$("#level2_div").append('<li class=\"guidetextimg\"><img src=\"http://image.bobaedream.co.kr/renew/images/common_re/mycarsearchtext07.gif\" alt=\"\" title=\"선택하신 세부모델은 등급이 없습니다.\" /></li>\n');
												} else {
												
  			 		    						$.each(response, function(val) {
																		
														temp_txt += '<li><input type="checkbox" name="level2_no[]" id="level_chk2_'    + 
																									response[val]['no']                                      + 
																									'" value="' + response[val]['no']                        + 
																									'" ><label style=\"cursor:pointer\" for="level_chk2_'    + 
																									response[val]['no']                                      + 
																									'">&nbsp;' + response[val]['name']                       + 
																									'</label></li>\n';                                
														});  
														
													$("#level2_div").append(temp_txt + '\n');
												 }
											} else if(level_select_cnt.length > 1){
												$("#level2_div").append('<li class=\"guidetextimg\"><img src=\"http://image.bobaedream.co.kr/renew/images/common_re/mycarsearchtext06.gif\" alt=\"\" title=\"모델 선택하시면 리스트가 열립니다.\" /></li>\n');
											} else if(level_select_cnt.length == 0){
												$("#level2_div").append('<li class=\"guidetextimg\"><img src=\"http://image.bobaedream.co.kr/renew/images/common_re/mycarsearchtext04.gif\" alt=\"\" title=\"세부모델을 선택하시면 리스트가 열립니다.\" /></li>\n');
											}

							}
      			}
  					, error: function(data, status, err) {
  					    alert('서버와의 통신이 실패했습니다.' + err);
  					    
  					  }
  					, complete: function() { 
  						//$('#ajax_load_indicator').fadeOut();
  					}
  			});
}

// 차종 공통

var depth  = "";



function car_depth_step(no, dep, hold) {
			var dummy     = new Date().getTime();
			var depth_txt = new Array("", "모델", "세부모델", "등급");
			var depth_id  = new Array("maker_no", "model_no", "level_no", "level2_no");
			
			if(no != "") {
			
				$.ajax({
  					type: 'get'
  					, async: true
  					, url: '/mycar/proc/car_depth_Cyber.php'
  					, data: "dummy=" + dummy + "&no=" + no + "&dep=" + dep
  					, dataType: 'json'
  					, beforeSend: function() {
  					     //$('#ajax_load_indicator').show().fadeIn('fast'); 
  					  }
  					, success: function(data) {
  			 		    var response = data;
						
						var dep_hold=dep;
						if(hold==true){
							dep_hold=dep_hold+1;
						} 
      	
      	
								for(var i=dep_hold; i<=3; i++) {									
									
									$("#" + depth_id[i] + " option").remove();
									$("#" + depth_id[i]).append('<option value="">' + depth_txt[i] + '</option>');

									
									if(hold==true){
										$(".selstrong").eq(i).text(depth_txt[i-1]);
									}else{
										$(".selstrong").eq(i).text(depth_txt[i]);
									}
									
								}
      					
      					var keytran ="";
      					
								$.each(response, function(keys) {
									keytran = "";
									$("#" + depth_id[dep]).append('<option value="' + keys.substr(1) + '">' + response[keys] + '</option>');
								});
 					  	}
  					, error: function(data, status, err) {
  					    alert('서버와의 통신이 실패했습니다.' + err);
  					    
  					  }
  					, complete: function() { 
  						//$('#ajax_load_indicator').fadeOut();
  					  }
  			});
  		} else {
  								for(var i=dep; i<=3; i++) {
									$("#" + depth_id[i] + " option").remove();
									$("#" + depth_id[i]).append('<option value="">' + depth_txt[i] + '</option>');
									$(".selstrong").eq(i).text(depth_txt[i]);
								}
  		}
}




function car_depth_step_new(no, dep, hold, tid) {
			var dummy     = new Date().getTime();
			var depth_txt = new Array("", "모델", "세부모델", "등급");
			var depth_id  = new Array("maker_no", "model_no", "level_no", "level2_no");
			
			if(no != "" && dep != 4) {
			
				$.ajax({
  					type: 'get'
  					, async: true
  					, url: '/mycar/proc/car_depth_Cyber.php'
  					, data: "dummy=" + dummy + "&no=" + no + "&dep=" + dep
  					, dataType: 'json'
  					, beforeSend: function() {
  					     //$('#ajax_load_indicator').show().fadeIn('fast'); 
  					  }
  					, success: function(data) {
  			 		    var response = data;
						
						var dep_hold=dep;
						if(hold==true){
							dep_hold=dep_hold+1;
						} 
      	
   	
      	
								for(var i=dep_hold; i<=3; i++) {									
									
									$("#" + depth_id[i] + " option").remove();
									$("#" + depth_id[i]).append('<option value="">' + depth_txt[i] + '</option>');

									$("#" + depth_id[i] + "_detail" + " option").remove();
									$("#" + depth_id[i] + "_detail").append('<option value="">' + depth_txt[i] + '</option>');


									
									if(hold==true){
										$(".selstrong").eq(i).text(depth_txt[i-1]);
									}else{
										
										$(".selstrong").eq(i).text(depth_txt[i]);
										$(".selstrong").eq(i + 8).text(depth_txt[i]);
									}
									
								}
      					
      					var keytran ="";
      					
								$.each(response, function(keys) {
									keytran = "";
									$("#" + depth_id[dep]).append('<option value="' + keys.substr(1) + '">' + response[keys] + '</option>');
									
									$("#" + depth_id[dep] + "_detail").append('<option value="' + keys.substr(1) + '">' + response[keys] + '</option>');
								});
								
								if(tid == "detail") {
									$("#" + depth_id[dep - 1]).val(no);
									$(".selstrong").eq(dep - 1).text(  $("#" + depth_id[dep - 1] + " option:selected").text()  );
									
								} else {
									$("#" + depth_id[dep - 1] + "_detail").val(no);
									
									$(".selstrong").eq(dep + 7).text(  $("#" + depth_id[dep - 1] + "_detail option:selected").text()  );

								}
								
								
 					  	}
  					, error: function(data, status, err) {
  					    alert('서버와의 통신이 실패했습니다.' + err);
  					    
  					  }
  					, complete: function() { 
  						//$('#ajax_load_indicator').fadeOut();
  					  }
  			});
  		} else {
  			

								if(tid == "detail") {
									$("#" + depth_id[dep - 1]).val(no);
									$(".selstrong").eq(dep - 1).text(  $("#" + depth_id[dep - 1] + " option:selected").text()  );
									
								} else {
									$("#" + depth_id[dep - 1] + "_detail").val(no);
									
									$(".selstrong").eq(dep + 7).text(  $("#" + depth_id[dep - 1] + "_detail option:selected").text()  );

								}  			
  			
  			
  			
  							for(var i=dep; i<=4; i++) {
									$("#" + depth_id[i] + " option").remove();
									$("#" + depth_id[i]).append('<option value="">' + depth_txt[i] + '</option>');
									
									$("#" + depth_id[i] + "_detail" + " option").remove();
									$("#" + depth_id[i] + "_detail").append('<option value="">' + depth_txt[i] + '</option>');

									
									$(".selstrong").eq(i).text(depth_txt[i]);
									$(".selstrong").eq(i + 8).text(depth_txt[i]);
								}
  		}
}

// 사이버 연식 변경
function car_year_change(obj) {

	var obj_chk = "";
	
	switch(obj.value) {
		case '0':
			obj_chk = "1";
			break;
		case '3':
			obj_chk = "2";
			break;
		default:
			obj_chk = "0";
			break;			
	}

	if(obj.name == "view_stat_detail") {
		eval('document.frm_search.view_stat[' + obj_chk + '].checked = true');
	} else {
		eval('document.frm_search.view_stat_detail[' + obj_chk + '].checked = true');
	}
}

// 검색 시 param 안보이게
function search_disable() {
	var input_list = $('#frm_search input, #frm_search select');
	input_list.each(function(a) {
		if(input_list[a].value == "") 
			input_list[a].disabled = true;
	});
}

// 정렬 토글(조회순, 마력순....) 
function order_toggle(ord) {

		var ord_txt = "";
		
		if( ord.substring(ord.length -1 )  == "1") { 
			ord_txt = ord.substr(0, ord.length -1) + "2";
		} else if( ord.substring(ord.length -1 ) == "2") { 
			ord_txt = ord.substr(0, ord.length -1) + "1";
		}
		document.frm_search.order.value = ord_txt;
		search_disable();
		document.frm_search.submit();
}

// 리스트 출력 갯수
function view_size_change(val) {
	
	$('#view_size').val( val );
	search_disable();
	document.frm_search.submit();
}

// 직거래 리스트 기간 순
function view_day(val) {
	
	$('#view_day').val( val );
	search_disable();
	document.frm_search.submit();
}

// 사이버 리스트 판매상태
function view_stat(val) {
	
	$('#view_stat').val( val );
	search_disable();
	document.frm_search.submit();
}

// 리스트 하단 검색 영역
function field2_search() {
	
	$('#search_field2').val( $("[name='s_field2']:checked").val() );
	$('#search_str2').val( $('#s_str2').val()  );
	search_disable();
	document.frm_search.submit();
}


// 검색조건 저장
function search_save() {
		
	$(".SearchCriteria").hide();
	
			$.ajax({
  				type: 'post'
  				, async: true
  				, url: '/mycar/proc/mycar_search_save.php'
  				, data: $('#frm_search').serialize()
  				, dataType: 'text'
  				, beforeSend: function() {
  				     //$('#ajax_load_indicator').show().fadeIn('fast'); 
  				  }
  				, success: function(data) {
  		 		    if(data == "login") {
  		 		    	   		    	window.open("https://security.bobaedream.co.kr/member/slogin_pop.php?pop=t_open&page="+encodeURIComponent(window.location.href),'login','width=400,height=290');
  		 		    } else if(data == "ok") {
  		 		    	if (confirm("검색조건이 정상적으로 저장되었습니다.\n\n저장된 항목을 확인하시겠습니까?")) {  
  		 		    		location.href="/mycar/manage/mycar_search_list.php";
  		 		    	}
  		 		    } else {
  		 		    	alert(data);
  		 		    }

 				  	}
  				, error: function(data, status, err) {
  				    alert('서버와의 통신이 실패했습니다.' + err);
  				    
  				  }
  				, complete: function() { 
  					//$('#ajax_load_indicator').fadeOut();
  				  }
  		});		
}

// 검색조건 리스트
function search_list(){
	//if(user_search_count <= 0){
	//	alert('저장된 검색조건이 없습니다.');
	//	return;
	//}
	location.href="/mycar/manage/mycar_search_list.php";
}


// 직거래 리스트 세부검색
function detailView() {
	
	// fakeselect에 선언되어 있음
	selectbox_close();
	
	$("#detailView").toggle();
	if( $("#detailView").css("display") == "none") {
		$("#detail_toggle_img").attr("src", "http://image.bobaedream.co.kr/renew/images/common/btn_detail_open.gif");
		$("#detail_search").val("");
	} else {
		$("#detail_toggle_img").attr("src", "http://image.bobaedream.co.kr/renew/images/common/btn_detail_close.gif");
		$("#detail_search").val("1");
	}
}

// 리스트 옵션 체크
function option_click(obj) {	
	var option_check   = "";

	var option_check_cnt = $("input:checkbox[id*='option_list_']:checked").length;

	if(	 option_check_cnt > 10 ) {
		
		$('#' + obj).attr('checked', false);
		alert('옵션은 10개까지만 선택하실 수 있습니다.');

		return false;
	}


	$.each($("input:checkbox[id*='option_list_']:checked"), function() {
		 option_check += $(this).val();
		 option_check += ','
	});	
	
	if(option_check != "") {
		option_check = option_check.substr(0, option_check.length - 1);
		$("#option_list").val(option_check);
	}	else {
		$("#option_list").val('');
	}
}

// 상세 옵션 펼치기
function opt_toggle(obj) {
	
	if( $(".dsearch_toggle_opt").css("display") == "none") {
		obj.src = "http://image.bobaedream.co.kr/renew/images/common_re/btn_search06.gif";
		$(".dsearch_toggle_opt").show();
	} else {

		$.each( $("input:checkbox[id*='option_list_']"), function() {
			$(this).attr("checked", false);
		});
		
		$("#option_list").val('');
		
		obj.src = "http://image.bobaedream.co.kr/renew/images/common_re/btn_search07.gif";
		$(".dsearch_toggle_opt").hide();
	}
}

// 직거래 검색 초기화
function search_reset_mycar() {
				
				// 직거래 제조사, 모델, 세부모델, 등급 초기화
				$("#maker_ul a").removeClass('choice');	
				$("#maker_no").val('');	
				divClear('a', 0);
				
				
				// selectbox 초기화
				var arrIndexes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
				$(".selstrong").filter(function(index) {
				    return arrIndexes.indexOf(index) > -1;
				}).text('선택');
				
				// select, checkbox, text 초기화
				$(".mycarsearch	select").val('');		
				$(".mycarsearch input:checkbox").attr('checked', false);		
				$(".mycarsearch input:text").val('');		

				$("[id*='_sel_span']").show();
				$("[id*='_txt_span']").hide();


				// 지역, 연료/변속기, 색상/배기량, 정원/구동방식 초기화
				$(".selstrong").eq(12).text('시/도');
				$(".selstrong").eq(13).text('구/군');
				$(".selstrong").eq(14).text('연료');
				$(".selstrong").eq(15).text('변속기');

				$(".selstrong").eq(16).text('색상');
				$(".selstrong").eq(17).text('배기량');
				$(".selstrong").eq(18).text('정원');
				$(".selstrong").eq(19).text('구동방식');
}


// 직거래 검색 초기화
function search_reset_cyber() {
				
				// selectbox 초기화
				var arrIndexes = [4, 5, 12, 13, 14, 15, 16, 17, 22, 23, 24, 25];
				$(".selstrong").filter(function(index) {
				    return arrIndexes.indexOf(index) > -1;
				}).text('선택');
				
				var depth_txt = new Array("제조사", "모델", "세부모델", "등급");
				var depth_id  = new Array("", "model_no", "level_no", "level2_no");

				
				for(var i=0; i<4; i++) {
					if(depth_id[i] != "") {
						$('#' + depth_id[i]).empty().append('<option>' + depth_txt[i] + '</option>');
						$('#' + depth_id[i] + '_detail').empty().append('<option>' + depth_txt[i] + '</option>');
					}
					
					$(".selstrong").eq(i).text(depth_txt[i]); 
					$(".selstrong").eq(i + 8).text(depth_txt[i]); 
					
				}
				
				// select, checkbox, text 초기화
				$(".basic select, .detailsearch01 select").val('');		
				$(".basic input:checkbox, .detailsearch01 input:checkbox, .detailsearch02 input:checkbox").attr('checked', false);		
				$(".basic input:text, .detailsearch01 input:text, .detailsearch02 input:text").val('');		

				$("[name='view_stat_detail']").eq(0).attr("checked", true);

				$("[id*='_sel_span']").show();
				$("[id*='_txt_span']").hide();


				// 지역, 연료/변속기, 색상/배기량, 정원/구동방식 초기화
				$(".selstrong").eq(6).text('시/도');
				$(".selstrong").eq(7).text('구/군');
				$(".selstrong").eq(18).text('시/도');
				$(".selstrong").eq(19).text('구/군');
				$(".selstrong").eq(20).text('연료');
				$(".selstrong").eq(21).text('변속기');
				$(".selstrong").eq(26).text('색상');
				$(".selstrong").eq(27).text('연비');
				$(".selstrong").eq(28).text('정원');
				$(".selstrong").eq(29).text('구동방식');
	
}



// textbox 엔터
function textbox_enter() {
	if(event.keyCode==13){
		search_disable();
		document.getElementById('frm_search').submit();

	}
}


/*************************************
 best100 search
 20120731 양승우
*************************************/


var str_cargubun 	=""; //차종
var str_cartype 	=""; //외형
var str_carchar 	=""; //특징
var str_carstate 	=""; //나라

var str_bestgubun 	=""; //일간 ,주간 ,월간 ,년간 ,명예    구분
var str_gubun 		=""; //사이버, 국산차, 수입차, 오토바이?
var str_wdate 		=""; //날짜
var str_rank 		=""; //랭킹 25개씩

//초기화
function best100_cancel(){
	 str_cargubun 	=""; //차종
	 str_cartype 	=""; //외형
	 str_carchar 	=""; //특징
	 str_carstate 	=""; //나라
	
	 str_bestgubun 	=""; //일간 ,주간 ,월간 ,년간 ,명예    구분
	 str_gubun 		=""; //사이버, 국산차, 수입차, 오토바이?
	 //str_wdate 		=""; //날짜
	 str_rank 		="1"; //랭킹 25개씩
	 
	 
	 $("[id^='A_best100theme_']").each(function(i,o){ //i:index, o:object		
		$("#A_best100theme_"+i).css({ 'font-weight':'normal' });
	});
	$("[id^='B_best100theme_']").each(function(i,o){ //i:index, o:object		
		$("#B_best100theme_"+i).css({ 'font-weight':'normal' });
	});
	$("[id^='C_best100theme_']").each(function(i,o){ //i:index, o:object		
		$("#C_best100theme_"+i).css({ 'font-weight':'normal' });
	});
	$("[id^='D_best100theme_']").each(function(i,o){ //i:index, o:object		
		$("#D_best100theme_"+i).css({ 'font-weight':'normal' });
	});
		
	$("#best100_tabBar_" + best100_oldbar).removeClass('on');
	$("#best100_tgubun_" + best100_oldtgubun).removeClass('on');
	$("#best100_rank_" + best100_oldrank).removeClass('on');
	$("#bbest100_rank_" + best100_oldrank).removeClass('on');
 
	 
	 

}

// -----  테마별 찾기 ---------- //
function best100_gubun_click(val) {	
	
	 
	/*
	$("[id^='"+val+"_best100theme_']").each(function(i,o){ //i:index, o:object		
		$("#"+val+"_best100theme_"+i).css({ 'font-weight':'normal' });
	});*/
	if (val!=="D"){
		$("[id^='A_best100theme_']").css({ 'font-weight':'normal' });
		$("[id^='B_best100theme_']").css({ 'font-weight':'normal' });
		$("[id^='C_best100theme_']").css({ 'font-weight':'normal' });
	}else{
		$("[id^='D_best100theme_']").css({ 'font-weight':'normal' });
	}
	
}

function best100_value(st1,st2,st3){  
	 	
	value_cancel();// value 초기화
		
	var str_val = st1+"_best100theme_"+st2;		
	
	if(document.getElementById(str_val).style.fontWeight=="bold" ) {		
		document.getElementById(str_val).style.fontWeight="normal";
	 
		st3=""; 
	}else{ 	
		//best100_gubun_click(st1); // 그룹초기화 
		//차종,외형,특징 초기화		 
		best100_gubun_click(st1);				
		 
		document.getElementById(str_val).style.fontWeight="bold";	
 
				
	}
	switch(st1){
			case "A":
				str_cargubun 	= st3; //차종
				str_cartype 	= "";
				str_carchar 	= "";				 
			break;
			case "B":				
				str_cargubun 	= "";
				str_cartype 	= st3; //외형
				str_carchar 	= "";				 
			break;
			case "C":				
				str_cargubun 	= "";
				str_cartype 	= "";
				str_carchar 	= st3; //특징				 
			break;
			case "D":				
				str_carstate 	= st3; //나라
			break;
			
		}
	//best100_DB(); 
	
}
var best100_oldbar;
//일간,주간,월간,연간,명예 tab bar
function best100_tabBar(val) {
		
		
 		value_cancel();// value 초기화
		
		var best100_tabBar = new Array('N','W','M','Y','G'); 
		
		if( best100_oldbar==val) {	//이전값 체크시
		
			/*
			if((document.getElementById("best100_tabBar_" + val).className).indexOf("on")>=0){
				$("#best100_tabBar_" + val).removeClass('on');	
				str_bestgubun = "";		
			}else{
				$("#best100_tabBar_" + val).addClass('on');	
				str_bestgubun = val;	
			}
			*/			
			//alert("1");
			
		}else{ // 다른곳
			$.each(best100_tabBar, function(vals) {
				$("#best100_tabBar_" + best100_tabBar[vals]).removeClass('on');
				
			});
			$("#best100_tabBar_" + val).addClass('on');
			str_bestgubun = val;
			best100_oldbar=val;		 
			//alert("2");
		
		}		
		//best100_DB();		
		
	 
		
}
	
var best100_oldtgubun;
//전체,사이버매장,국산,수입,오토바이
function best100_tgubun(val) {

value_cancel();// value 초기화

var best100_tgubun = new Array('A','B','C','D','E'); 

if(val=="E"){//오토바이

	//나라 빼고 모두초기화 
	//테마별, 베스트탭
	str_cargubun 	=""; //차종
	str_cartype 	=""; //외형
	str_carchar 	=""; //특징
	str_carstate 	=""; //나라
	
	//str_bestgubun 	=""; //일간 ,주간 ,월간 ,년간 ,명예    구분
	str_gubun 		=val; //사이버, 국산차, 수입차, 오토바이?
	best100_oldtgubun=val;
	
	$("[id^='A_best100theme_']").each(function(i,o){ //i:index, o:object		
		$("#A_best100theme_"+i).css({ 'font-weight':'normal' });
	});
	$("[id^='B_best100theme_']").each(function(i,o){ //i:index, o:object		
		$("#B_best100theme_"+i).css({ 'font-weight':'normal' });
	});
	$("[id^='C_best100theme_']").each(function(i,o){ //i:index, o:object		
		$("#C_best100theme_"+i).css({ 'font-weight':'normal' });
	});
	
	 
	$("[id^='D_best100theme_']").each(function(i,o){ //i:index, o:object		
		$("#D_best100theme_"+i).css({ 'font-weight':'normal' });
	});
	 	
	//$("#best100_tabBar_" + best100_oldbar).removeClass('on'); //일간 ,주간 ,월간 ,년간 ,명예    구분


	$.each(best100_tgubun, function(vals) {
		$("#best100_tgubun_" + best100_tgubun[vals]).removeClass('on');
				 
		});
	$("#best100_tgubun_" + val).addClass('on');
 

}else{
		
		
		
		if( best100_oldtgubun==val) {	
		/*
			if((document.getElementById("best100_tgubun_" + val).className).indexOf("on")>=0){			
				$("#best100_tgubun_" + val).removeClass('on');	
				str_gubun = "";		
				//alert("1-1");
			}else{				
				$("#best100_tgubun_" + val).addClass('on');
				str_gubun = val;	
				//alert("1-2");
			}			
		*/	
		}else{ // 다른곳
			$.each(best100_tgubun, function(vals) {
				$("#best100_tgubun_" + best100_tgubun[vals]).removeClass('on');
				 
			});
			$("#best100_tgubun_" + val).addClass('on');
			str_gubun = val;
			best100_oldtgubun=val;		 
			//alert("2");
		
		}		
}


		//best100_DB();		
		
}
	 
var best100_oldrank;
//25,50,75,100
function best100_rank(val) {
		
		var best100_rank = new Array('1','26','51','76'); 
		
		if( best100_oldrank==val) {	
			
		 		
			
		}else{ // 다른곳
			$.each(best100_rank, function(vals) {
				$("#best100_rank_" + best100_rank[vals]).removeClass('on');
				$("#bbest100_rank_" + best100_rank[vals]).removeClass('on');
				
				 
			});
			$("#best100_rank_" + val).addClass('on');
			$("#bbest100_rank_" + val).addClass('on');
			str_rank = val;
			best100_oldrank=val;		 
			//alert("2");
		
		}		
		//best100_DB();		
		
}



//mycar 미리보기 popup
function mycar_carviewPopup(g,z,n,path){

var uri;

if (g=="cyber" ){//car 
	uri = "/"+path+"/popup/popCarView.php?tbl="+g+"&imgID=1&zone="+z+"&no="+n;
	wi=930;
	he=750;
}else if ( g=="mycar"){ //mycar
	uri = "/"+path+"/popup/popCarView.php?tbl="+g+"&imgID=1&zone="+z+"&no="+n;
	wi=930;
	he=750;
}else if (g=="bike_cyber" || g=="bike_market"){ //bike
	uri = "/bike2/popCarView.php?imgID=1&zone="+z+"&no="+n;
	wi=900;
	he=630;
}
 
 	viewWindow = window.open(uri, "carViewWin", 'width='+wi+',height='+he+',top=80,toobar=no,scrollbars=no,menubar=no,status=no,directories=no');	
	viewWindow.focus();
 
}

//사이버, 직거래 리스트 미리보기 새창
function mycar_carviewWindow(g,z,n,path){

	var uri;
	
	if(g == "cyber")
		uri = "/cyber/CyberCar_view.php?gubun=" + z + "&no=" + n; 
	else if(g == "mycar")
 		uri = "/mycar/mycar_view.php?gubun=" + z + "&no=" + n; 
 	
 	viewWindow = window.open(uri, "");	
}

//선택차량 비교하기
function  selectcar_ad(path){
	
var chk_count = 0;
var chk_value="";
 
 $("input[id=checklist1[]]:checkbox:checked").each(function() {
  		
	chk_value = chk_value+ $(this).val()+"#";	
	chk_count++;
	
  });

  if (chk_count < 2) {
   alert('선택비교는 2대이상 체크 하세요');
   return;
  }
  if (chk_count > 5) {
   alert('선택비교는 최대 4대까지 가능합니다.');
   $("input[name=check1[]]").attr("checked",false);
   return;
  }

chk_value = encodeURIComponent(chk_value);
//alert(chk_value);

window.open("/"+path+"/popup/pop_selectcar.php?chk="+chk_value,"selectcar_ad","width=900, height=700 ");
	
}

//value 초기화
function value_cancel(){

		
	$("#best100_rank_" + best100_oldrank).removeClass('on');	
	$("#best100_rank_1").addClass('on');	
	$("#bbest100_rank_" + best100_oldrank).removeClass('on');	
	$("#bbest100_rank_1").addClass('on');	
	
	str_rank = 1;	
	best100_oldrank="";
	
	
	$("#best100_tgubun_" + best100_oldtgubun).removeClass('on');
	$("#best100_tgubun_A").addClass('on');	
	best100_oldtgubun="";
	str_gubun = "A";


}


//
function GetXmlHttpObject(){
	
var objXMLHttp=null;
	if (window.XMLHttpRequest)
	{
		objXMLHttp = new 	XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
			
}






var xmlHttp;
//1대 찜하기
function zzim_ad_one(str,path){


var chk_value; 
chk_value =  $("#"+str).val()+"#";	 

if(chk_value == "undefined#") {
	chk_value =  str+"#";	 
}

chk_value = encodeURIComponent(chk_value);	


xmlHttp = 	GetXmlHttpObject();
if (xmlHttp==null)
{
	alert("Browser does not support HTTP Request");
	return;
}	
var url = "/"+path+"/proc/zzim_ad.php?mode=sainput";	
 
url = url + "&chk_value="+chk_value;
url = url + "&path="+path;

xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

 
}

function stateChanged(){	
	//if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
	//	alert(xmlHttp.responseText);
	//}
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		
		var respOk = new Array();
		var date_responseText = xmlHttp.responseText;
		respOk = date_responseText.split("|");
		
		if(respOk[1]){
			if(confirm(respOk[0])==true){
				if( respOk[1] == "/member/login_pop.php"){ //비로그인시 팝업
										
					window.open("https://security.bobaedream.co.kr/member/slogin_pop.php?t_open&page="+encodeURIComponent(window.location.href),'login','width=400,height=290');
				}else{
					//top.location.href = respOk[1];	
					window.open(respOk[1]);	
				}
			}
		}else{
			alert(respOk[0]);
		}
				
	}		
}



//선택차량 찜하기
function zzim_ad(path){
	
// value : gubun/no/zone 

var chk_count = 0;
var chk_value="";


 $("input[id=checklist1[]]:checkbox:checked").each(function() {
  		
	chk_value = chk_value+ $(this).val()+"#";	
	chk_count++;
	
  });
  
  
  if (chk_count == 0) {
   alert('한개이상 체크 하세요');
   return;
  }
/*    
  if (chk_count > 5) {
   alert('5개 이하만 체크 하세요');
   $("input[name=check1[]]").attr("checked",false);
   return;
  }
*/

//alert(chk_value);
chk_value = encodeURIComponent(chk_value);

xmlHttp = 	GetXmlHttpObject();
if (xmlHttp==null)
{
	alert("Browser does not support HTTP Request");
	return;
}	
var url = "/"+path+"/proc/zzim_ad.php?mode=sainput";	
 
url = url + "&chk_value="+chk_value;
url = url + "&path="+path;

xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
 

	
	
}

//wopen
function wopen(url, t, w, h) {
    var sw;
    var sh;
    sw = (screen.Width - w) / 2;
    sh = (screen.Height - h) / 2;
    window.open(url, t, 'Width='+w+'px, Height='+h+'px, Left='+sw+', Top='+sh);
}


//체크전체선택 해제
function checklist_all(){

 
   if ($("#check_all").attr("checked") == true) {
    $("input[id=checklist1[]]").attr("checked",true);
   } else {
    $("input[id=checklist1[]]").attr("checked",false);
   }
    
}

// 날짜 범위
// fakeselect 는 jquery로 이벤트 설정할 수 없음. function으로 빼야 함
function year_remove(obj, obj2, same) {
//12,13

	var sel_no = "";
	var label_txt   = "선택";
	var id1 = "";
	var id2 = "";
	
	if(obj.substr(-7) == '_detail') {
		id1 = obj;
		id2 = obj.substr(0, obj.length - 7);
		
	} else {
		id1 = obj;
		id2 = obj + "_detail";
	}

	sel_no  = $("select").index( $("#" + id1 + "_2_s") );
	sel_no2 = $("select").index( $("#" + id2 + "_2_s") );

	$('#' + id1 + '_2_s option').remove();
	$('#' + id2 + '_2_s option').remove();

  $(".selstrong")
         .eq(sel_no2 - 1)
         .text($('#' + id1 + '_1_s option:selected').text());

	$('#' + id2 + '_1_s').val($('#' + id1 + '_1_s').val());

  
  $(".selstrong")
         .eq(sel_no)
         .text(label_txt);

  $(".selstrong")
         .eq(sel_no2)
         .text(label_txt);




	$('#' + id1 + '_2_s' ).append("<option value=''>선택</option>");	
	$('#' + id2 + '_2_s' ).append("<option value=''>선택</option>");	
	
	$.each( $('#' + id1 + '_1_s option') , function() {
		  if(same == "Y") {
		  	if( Number(this.value) >= Number(obj2) ){
		  		$('#' + id1 + '_2_s' ).append("<option value='" + this.value + "'>" + this.text + "</option>");
		  		$('#' + id2 + '_2_s' ).append("<option value='" + this.value + "'>" + this.text + "</option>");
		  	}
		  } else {
		  	if( Number(this.value) > Number(obj2) ){
		  		$('#' + id1 + '_2_s' ).append("<option value='" + this.value + "'>" + this.text + "</option>");
		  		$('#' + id2 + '_2_s' ).append("<option value='" + this.value + "'>" + this.text + "</option>");
		  	}
		  }
	});

}

function year_remove_second(obj) {
	var sel_no2 = "";
	
	var id1 = "";
	var id2 = "";
	
	if(obj.substr(-7) == '_detail') {
		id1 = obj;
		id2 = obj.substr(0, obj.length - 7);
	} else {
		id1 = obj;
		id2 = obj + "_detail";
	}	
	
	sel_no2 = $("select").index( $("#" + id2 + "_2_s") );

  $(".selstrong")
         .eq(sel_no2)
         .text($('#' + id1 + '_2_s option:selected').text());

	$('#' + id2 + '_2_s').val($('#' + id1 + '_2_s').val());	
	
}


// 셀렉트박스 직접입력 
function select_toggle(obj) {
	
	// fakeselect에 선언되어 있음
	selectbox_close();
	
	var label_txt   = "선택";
	var sel_no = "";
		$("#" + obj + "_1_txt").val('');
		$("#" + obj + "_2_txt").val('');
		$("#" + obj + "_1_s").val('');
		$('#' + obj + '_2_s option').remove();

		sel_no = $("select").index( $("#" + obj + "_1_s") );

  	$(".selstrong")         
  	       .eq(sel_no)      
  	       .text(label_txt);
  	$(".selstrong")         
  	       .eq(sel_no + 1)      
  	       .text(label_txt);
		
		$.each( $('#' + obj + '_1_s option') , function() {
			  	$('#' + obj + '_2_s' ).append("<option value='" + this.value + "'>" + this.text + "</option>");
		});		
	
	
	
	$("#" + obj + "_sel_span").toggle();
	$("#" + obj + "_txt_span").toggle();
	
}
   

// selectbox 범위
function select_remove(obj, obj2, same) {
	var sel_no = "";
	var label_txt   = "선택";

	sel_no = $("select").index( $("#" + obj + "_2_s") );

	$('#' + obj + '_2_s option').remove();

  $(".selstrong")
         .eq(sel_no)
         .text(label_txt);

	$('#' + obj + '_2_s' ).append("<option value=''>선택</option>");	
	$.each( $('#' + obj + '_1_s option') , function() {
		
			
		
		  if(same == "Y") {
		  	
		  	if( obj2 == 'P0' && Number(this.value) ){
		  		$('#' + obj + '_2_s' ).append("<option value='" + this.value + "'>" + this.text + "</option>");
		  	} else if( Number(this.value) >= Number(obj2) )
		  		$('#' + obj + '_2_s' ).append("<option value='" + this.value + "'>" + this.text + "</option>");
		  } else {
		  	if( obj2 == 'P0' && Number(this.value)) {
		  		$('#' + obj + '_2_s' ).append("<option value='" + this.value + "'>" + this.text + "</option>");
		  	} else if( Number(this.value) > Number(obj2) )
		  		$('#' + obj + '_2_s' ).append("<option value='" + this.value + "'>" + this.text + "</option>");
		  }
	});

}   



// selectbox 범위(연식)
// 상세검색 시 연도범위가 같을 경우 달도 변경

function select_remove_year(obj, obj2, same) {
	var sel_no       = "";
	var label_txt    = "선택";
	var sel_txt_flag = "";
	
	var chg_obj      = "";
	var chg_s_obj    = "";
	var chg_o_obj    = obj;
	
	// 상세검색이 아닐 경우
	// 일반검색 연식과 sync한다
	var s_search = obj.substr(obj.length - 2, 2);

	if(s_search == '_s') {
		chg_s_obj = obj.substr(0, obj.length - 2);
		obj       = obj.substr(0, obj.length - 2);
	}
	
	
	
	switch(obj) {
		case 'buy_year1_1':
			chg_obj = "buy_year2_1";
			break;
		case 'buy_year1_2':
			chg_obj = "buy_year2_2";
			break;
		default:
			break;			
	}

	if(obj == 'buy_year2_1') {
		obj  = 'buy_year1_2'
		obj2 = $('#buy_year1_2').val();
		chg_obj = "buy_year2_2";
	}

	sel_no  = $("select").index( $("#" + chg_obj) );
	sel_no2 = $("select").index( $("#" + chg_obj + "_s") );

	$("#" + chg_obj + " option").remove();
	$("#" + chg_obj + "_s option").remove();
  
  $(".selstrong")
         .eq(sel_no)
         .text(label_txt);

	if(sel_no2 > 0) {
  $(".selstrong")
         .eq(sel_no2)
         .text(label_txt);
	}
	
	
	$.each( $('#' + obj + ' option') , function() {
		  	if(same == "Y") {
		  		
		  		if(obj == 'buy_year1_2') {
		  			
		  			if( $('#buy_year1_1').val() == $('#buy_year2_1').val()) { 
		  				if((obj2 == '' || obj2 == '00') && this.value == '00') {
		  					$('#' + chg_obj ).append("<option value='00'>0</option>");
		  				}
		  				if( Number(this.value) != 0 && Number(this.value) >= Number(obj2) ) {
		  						$('#' + chg_obj ).append("<option value='" + this.value + "'>" + this.text + "</option>");
		  				}
		  			} else {
		  				$('#' + chg_obj ).append("<option value='" + this.value + "'>" + this.text + "</option>"); 
		  				sel_txt_flag = true;
		  			}
		  				
		  				
		  		} else {
		  			
		  			if( Number(this.value) >= Number(obj2) ) {
		  				$('#' + chg_obj ).append("<option value='" + this.value + "'>" + this.text + "</option>");
		  				$('#' + chg_obj + '_s').append("<option value='" + this.value + "'>" + this.text + "</option>");
		  			}
		  		}
		  		
		  	} else {
		  		if( Number(this.value) > Number(obj2) ) {
		  			$('#' + chg_obj ).append("<option value='" + this.value + "'>" + this.text + "</option>");
		  			$('#' + chg_obj + '_s').append("<option value='" + this.value + "'>" + this.text + "</option>");
		  		}
		  	}
	});
	if(sel_txt_flag	!= true && obj2 != "") 
		$('#' + chg_obj).prepend("<option value=''>선택</option>");

	if(sel_txt_flag	!= true && obj2 != "") 
		$('#' + chg_obj + '_s').prepend("<option value=''>선택</option>");


	
	var obj_val = "";
	
	if(s_search == '_s') {
	
		obj_val = $('#' + chg_s_obj + '_s').val();
		if(obj_val == "") {
			obj_val = label_txt;
		}
				
		$('#' + chg_s_obj).val( $('#' + chg_s_obj + '_s').val() );
		
  	$(".selstrong")
  	       .eq($("select").index( $("#" + chg_s_obj) ))
  	       .text(obj_val);
	} else {
		
		if( obj.substr(-3) == '1_1') {


			obj_val = $('#' + obj).val();
			if(obj_val == "") {
				obj_val = label_txt;
			}


			$('#' + obj + '_s').val( $('#' + obj).val()  );
			
  		$(".selstrong")
  		       .eq($("select").index( $('#' + obj + '_s') ))
  		       .text( obj_val );
		
		} else if( chg_o_obj.substr(-3) == '2_1' ) {

			obj_val = $('#' + chg_o_obj).val();
			
			if(obj_val == "") {
				obj_val = label_txt;
			}
			
			$('#' + chg_o_obj + '_s').val( $('#' + chg_o_obj).val()  );

  		$(".selstrong")
  		       .eq($("select").index( $('#' + chg_o_obj + '_s') ))
  		       .text(obj_val);
			
		}
	}
}   

function select_year_clear() {
	
	
	$("#buy_year2_2 option").remove();
	$.each( $('#buy_year1_2 option') , function() {  
		$("#buy_year2_2").append("<option value='" + this.value + "'>" + this.text + "</option>");
	});
	
	
	for(var i=1; i<=2; i++) {
		$("#buy_year" + i + "_2").val('');
		$(".selstrong")
         .eq($("select").index( $("#buy_year" + i + "_2") ))
         .text("선택");
		$("#buy_year" + i + "_2").val('');  	       
	}
	
	
	
}



// 제조사 전체/국산/수입 변경시 이벤트
function change_maker_list(obj) {
	if(obj == "ALL") {
		$(".gubun_1").show();
		$(".gubun_0").show();
		$("#make_sort_div span").removeClass("choice");
		$("#make_sort_div span").eq(1).addClass("choice");
		$("#sel_m_gubun").val('ALL');
		$("#gubun").val(ori_gubun);
	} else 	if(obj == "K") {
		$(".gubun_1").show();
		$(".gubun_0").hide();
		$("#make_sort_div span").removeClass("choice");
		$("#make_sort_div span").eq(3).addClass("choice");
		$("#sel_m_gubun").val('');
		$("#gubun").val("K");
	}	else if(obj == "I") {
		$(".gubun_1").hide();
		$(".gubun_0").show();
		$("#make_sort_div span").removeClass("choice");
		$("#make_sort_div span").eq(4).addClass("choice");
		$("#sel_m_gubun").val('');
		$("#gubun").val('I');
	}
	
		var lst_arr     = new Array("model_div", "level_div", "level2_div");
		var lst_txt_arr = new Array("<li class=\"guidetextimg\"><img src=\"http://image.bobaedream.co.kr/renew/images/common_re/mycarsearchtext01.gif\" alt=\"\" title=\"제조사를 선택하시면 리스트가 열립니다.\" /></li>", 
																"<li class=\"guidetextimg\"><img src=\"http://image.bobaedream.co.kr/renew/images/common_re/mycarsearchtext02.gif\" alt=\"\" title=\"모델 선택하시면 리스트가 열립니다.\" /></li>", 
																"<li class=\"guidetextimg\"><img src=\"http://image.bobaedream.co.kr/renew/images/common_re/mycarsearchtext04.gif\" alt=\"\" title=\"세부모델을 선택하시면 리스트가 열립니다.\" /></li>"
																);

				
		for(var i=0; i<=2; i++) {
	  		$("#" + lst_arr[i] + " li").remove();  
	  		$("#" + lst_arr[i] + " ul").remove();  
  			$("#" + lst_arr[i] + " p").remove();   
		}
  			
		for(var i=0; i<=2; i++) {
		
  				$("#" + lst_arr[i]).append(lst_txt_arr[i]);
  	}
  	
  	$("a[id*='car_kind_']").removeClass("choice");
  	$("#maker_no").removeClass("choice");
  	$("#maker_no").val('');
  	//$("#gubun").val(ori_gubun);
}

// 직거래 레이어팝업 클릭 시 이벤트
function maker_layer() {

	if($("#make_sort_div span").eq(1).attr('class') == "choice") {
		$("#layer_maker_A").toggle();
	} else if($("#make_sort_div span").eq(3).attr('class') == "choice") {
		$("#layer_maker_K").toggle();
	} else if($("#make_sort_div span").eq(4).attr('class') == "choice") {
		$("#layer_maker_I").toggle();
	}
}

function maker_layer_click(obj, obj2, obj3, l_gubun) {
	$("#gubun").val(l_gubun);
	car_depth(obj, obj2, obj3);
	maker_layer();
	$('#car_kind_' + obj3).focus();
}


// 검색조건 보기
function search_view_open(obj) {
	$.ajax({
  		type: 'post'
  		, async: true
  		, url: '/mycar/proc/mycar_search_view.php'
  		, dataType: 'json'
  		, beforeSend: function() {
  		     //$('#ajax_load_indicator').show().fadeIn('fast'); 
  		  }
  		, success: function(data) {

   		    if(data['tot'] == "LOGIN") {
   		    	window.open("https://security.bobaedream.co.kr/member/slogin_pop.php?pop=t_open&page="+encodeURIComponent(window.location.href),'login','width=400,height=290');
   		    } else if(data['tot'] == "0") {
   		    	alert("저장된 검색조건이 없습니다.");
   		    } else {

						
							$("#search_view" + obj + " li").remove();
							$.each(data['list'], function () {
								$("#search_view" + obj).append('<li><div onclick="location.href=\'' + 
																								this.refer_page + '?' + this.param + 
																							  '\'" style=\"cursor:pointer;width:150px;text-overflow:ellipsis;overflow:hidden;-o-text-overow: ellipsis;white-space:nowrap; display:inline-block;float;left\">' + 
																							  this.subject + 
																							  '</div><a href="javascript:search_del_layer(\'' + this.no + '\', \'' + obj +'\');" class="del">삭제</a></li>');
							});

   		    	if(obj == "1") {
							$(".SearchCriteria").eq(0).hide();
							$(".SearchCriteria").eq(1).toggle();		
						} else if(obj == "2") {
							$(".SearchCriteria").eq(1).hide();
							$(".SearchCriteria").eq(0).toggle();		
						}
							

						$("#search_view" + obj).append('<li class="end">' + 
																					 '<a href="#" class="left">' +
																					 '<img src="http://image.bobaedream.co.kr/renew/images/common_re/btn_pop_left.gif" alt="" class="pointer" />' +
											                     '</a>' +
											                     '<span>1/1</span>' +
											                     '<a href="#" class="right">' +
											                     '<img src="http://image.bobaedream.co.kr/renew/images/common_re/btn_pop_right.gif" alt="" class="pointer" />' +
											                     '</a>' +
										                       '</li>' +
										                       '<li class="btn_close"><a href="javascript:SearchCriteria_close();">' + 
										                       '<img src="http://image.bobaedream.co.kr/renew/images/common_re/btn_pop_close.gif" alt="닫기" class="pointer" /></a></li>');

							
							
   		    }
 		  	}
  		, error: function(data, status, err) {
  		    alert('서버와의 통신이 실패했습니다.' + err);
  		    
  		  }
  		, complete: function() { 
  			//$('#ajax_load_indicator').fadeOut();
  		  }
  });		
}

function SearchCriteria_close() {
	$(".SearchCriteria").hide();
}

function search_del_layer(obj, obj2) {

 	if(obj2 == "1") {
		$(".SearchCriteria").eq(1).toggle();		
	} else if(obj2 == "2") {
		$(".SearchCriteria").eq(0).toggle();		
	}
	
	$.ajax({
  		type: 'post'
  		, async: true
  		, url: '/mycar/proc/search_del_layer.php'
  		, data: 'chk_no=' + obj
  		, dataType: 'text'
  		, beforeSend: function() {
  		     //$('#ajax_load_indicator').show().fadeIn('fast'); 
  		  }
  		, success: function(data) {
  				
   		    if(data == "FALSE") {
   		    	alert('삭제에 실패했습니다');
   		    } else if(data == "OK") {
   		    	search_view_open(obj2);
   		    }
 		  	}
  		, error: function(data, status, err) {
  		    alert('서버와의 통신이 실패했습니다.' + err);
  		    
  		  }
  		, complete: function() { 
  			//$('#ajax_load_indicator').fadeOut();
  		  }
  });		
	
	
}



// 직거래 차량찾기 검색(볼드)
function search_car_bold(ord) {

	if( $("#search_car").val() == ord) {
		$("#search_car").val("");
	} else {
		$("#search_car").val(ord);
	}

	search_disable();
	document.frm_search.submit();
}
